import { getFiledValue } from "./utils";


// 文本框配置
export const textFieldConfig = {
  type: 'object',
  name: '文本输入框',
  properties: {
    label: {
      type: 'string',
      description: '表单标签',
      value: ''
    },
    field: {
      type: 'string',
      description: '字段名称',
      disabled: true, // 输入框是否禁用
      value: getFiledValue()
    },
    defaultValue: {
      type: 'string',
      description: '默认值',
      value: ''
    },
    tooltip: {
      type: 'string',
      description: '提示语',
      value: ''
    },
    placeholder: {
      type: 'string',
      description: '占位文本',
      value: '请输入'
    },
    inputType: {
      type: 'radio_group',
      description: '输入框类型',
      value: 'text'
    },
    hidden: {
      type: 'switch',
      description: '是否隐藏',
      value: false
    },
    disabled: {
      type: 'switch',
      description: '是否禁用',
      value: false
    },
    required: {
      type: 'switch',
      description: '是否必填',
      value: false
    },
    clearble: {
      type: 'switch',
      description: '显示清除按钮',
      value: false
    }
  },
  // 数据源
  data: {},
  // 样式
  style: {},

  // 校验规则
  rules: {
    filedType: {
      type: 'select',
      description: '字段值类型',
      value: undefined,
      options: [
        {
          label: '普通文本',
          value: 'string'
        },
        {
          label: '整数',
          value: 'number'
        },
        {
          label: '小数',
          value: 'decimal'
        },
        {
          label: '手机号',
          value: 'phone'
        },
        {
          label: '邮箱',
          value: 'email'
        },
        {
          label: '网址',
          value: 'url'
        }
      ],
      extends: {
        string: [
          {
            type: 'number',
            description: '最大输入长度',
            value: undefined
          },
          {
            type: 'number',
            description: '最小输入长度',
            value: undefined
          },
          {
            type: 'select',
            description: '其它条件',
            value: undefined,
            multiple: true,
            // todo... value 应是正则
            options: [
              {
                label: '只能输入数字',
                value: 'number'
              },
              {
                label: '只能输入字母',
                value: 'decimal'
              },
              {
                label: '只能输入中文',
                value: 'phone'
              },
              {
                label: '只能输入数字+字母',
                value: 'num+letter'
              },
              {
                label: '不允许出现特殊字符',
                value: 'email'
              }
            ]
          }
        ],
        number: [
          {
            type: 'number',
            description: '最大值',
            value: undefined
          },
          {
            type: 'number',
            description: '最小值',
            value: undefined
          }
        ],
        decimal: [
          {
            type: 'number',
            description: '最大值',
            value: undefined
          },
          {
            type: 'number',
            description: '最小值',
            value: undefined
          },
          {
            type: 'number',
            description: '小数点位数',
            value: undefined
          }
        ]
      }
    },

    trigger: {
      type: 'select',
      description: '触发类型',
      value: undefined,
      options: [
        {
          label: '输入内容改变时',
          value: 'input'
        },
        {
          label: '输入框失焦时',
          value: 'blur'
        }
      ],
      extends: {}
    }
  }
}
